package com.example.pcl.controller.admin;

import com.example.pcl.constant.MessageConstants;
import com.example.pcl.pojo.dto.NotificationsDTO;
import com.example.pcl.pojo.dto.NotificationsFilterDTO;
import com.example.pcl.pojo.vo.NotificationsVO;
import com.example.pcl.result.PageResult;
import com.example.pcl.result.Result;
import com.example.pcl.service.INotificationsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 通知表，存储与用户和心理咨询师相关的各种预约通知 前端控制器
 * </p>
 *
 * @author xx
 * @since 2024-12-17
 */
@RestController("adminNotificationsController")
@RequestMapping("/admin/notifications")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "管理端通知相关接口")
public class NotificationsController {

    private final INotificationsService notificationsService;

    /**
     * 查询通知列表
     *
     * @param filterDTO 筛选条件 DTO
     * @return 分页后的通知列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询通知列表")
    public Result<?> listNotifications(NotificationsFilterDTO filterDTO) {
        log.info("管理员查询通知列表，筛选条件: {}", filterDTO);
        PageResult<NotificationsVO> result = notificationsService.listNotifications(filterDTO);
        return Result.success(result, MessageConstants.SELECT_OK);
    }

    /**
     * 新增通知
     *
     * @param notificationsDTO 通知数据
     * @return 操作结果
     */
    @PostMapping("/add")
    @Operation(summary = "新增通知")
    public Result<?> addNotification(@RequestBody @Validated NotificationsDTO notificationsDTO) {
        log.info("管理员新增通知: {}", notificationsDTO);
        notificationsService.addNotification(notificationsDTO);
        return Result.success(MessageConstants.ADD_OK);
    }

    /**
     * 修改通知
     *
     * @param notificationsDTO 修改的通知数据
     * @return 操作结果
     */
    @PutMapping("/update")
    @Operation(summary = "修改通知")
    public Result<?> updateNotification(@RequestBody @Validated NotificationsDTO notificationsDTO) {
        log.info("管理员修改通知: {}", notificationsDTO);
        notificationsService.updateNotification(notificationsDTO);
        return Result.success(MessageConstants.OPERATION_SUCCESSFUL);
    }

    /**
     * 删除通知
     *
     * @param notificationId 通知ID
     * @return 操作结果
     */
    @DeleteMapping("/delete/{notificationId}")
    @Operation(summary = "删除通知")
    public Result<?> deleteNotification(@PathVariable Integer notificationId) {
        log.info("管理员删除通知ID: {}", notificationId);
        notificationsService.deleteNotification(notificationId);
        return Result.success(MessageConstants.OPERATION_SUCCESSFUL);
    }

    /**
     * 获取通知详细
     *
     * @param id 通知id
     * @return 通知实体
     */
    @GetMapping("/detail/{id}")
    @Operation(summary = "获取通知详细")
    public Result<?> detail(@PathVariable Integer id) {
        log.info("管理员获取通知详细:{}", id);
        return Result.success(notificationsService.finById(id), MessageConstants.SELECT_OK);
    }
}